<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>root和parent</h2>
      <child></child>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const { createApp } = Vue;

      // this.$root表示的根组件实例
      // this.$parent表示父组件实例

      const Child2 = {
        template: `
          <div>这是child2子组件</div>
        `,
        mounted() {
          // console.log(this.$root.msg);
          // this.$root.fn();
          console.log(this.$parent);
        },
      };

      const Child = {
        data() {
          return {
            name: "zhangsan",
          };
        },
        template: `
          <div>
            <div>这是child子组件</div>
            <child2></child2>
          </div>
        `,
        mounted() {
          console.log(this);
        },
        components: {
          Child2,
        },
      };

      const app = createApp({
        data() {
          return {
            count: 10,
            msg: "hello",
          };
        },
        methods: {
          fn() {
            console.log("fn");
          },
        },
        mounted() {
          // console.log("app", this);
        },
        components: {
          Child,
        },
      });

      app.mount("#app");
    </script>
  </body>
</html>
